# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=intel-media-sdk
pkgver=23.2.2
pkgrel=0
pkgdesc="Hardware-accelerated video processing on Intel integrated GPUs"
url="http://mediasdk.intel.com/"
arch="x86_64"
license="MIT"
depends="libmfx=$pkgver-r$pkgrel"
depends_dev="libva-dev"
checkdepends="gtest-dev"
makedepends="
	$depends_dev
	cmake
	libx11-dev
	ninja
	wayland-dev
	"
subpackages="$pkgname-tracer $pkgname-dev libmfx"
source="https://github.com/Intel-Media-SDK/MediaSDK/archive/intel-mediasdk-$pkgver.tar.gz
	gcc13.patch
	musl-compat.patch
	"
builddir="$srcdir/MediaSDK-intel-mediasdk-$pkgver"

build() {
	# CMAKE_BUILD_TYPE=Release - do not change to None!
	cmake -G Ninja -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DENABLE_OPENCL=ON \
		-DENABLE_X11_DRI3=ON \
		-DENABLE_WAYLAND=ON \
		-DENABLE_TEXTLOG=ON \
		-DENABLE_STAT=ON \
		-DBUILD_SAMPLES=OFF \
		-DBUILD_TOOLS=OFF \
		-DBUILD_TUTORIALS=OFF \
		-DBUILD_TESTS=$(want_check && echo ON || echo OFF) \
		-DUSE_SYSTEM_GTEST=$(want_check && echo ON || echo OFF)
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

tracer() {
	pkgdesc="Intel Media SDK Tracer"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin/mfx-tracer-config
	amove usr/lib/libmfx-tracer.so.*
}

libmfx() {
	pkgdesc="Intel Media SDK dispatcher library"
	depends=""

	amove usr/lib/libmfx.so.*
}

sha512sums="
d4cfebee4f689b93c0171775ff2bab449f801c55822c5b800fe3217653d197216cf2a95dea115cf51f308e158adea7a271f03081b011e024c16bf7915fdcd586  intel-mediasdk-23.2.2.tar.gz
104c20259c00cff0a9e6c9dbd5ffae6dfb5e05fb25065735310a4a389da1dd46bff1bbaffa71b1dff0dbd3b79f80a169f34abd7da08ff438dd3c2a2f00c326fd  gcc13.patch
c04a538a3699a0d4a94b80e1d4b7de2e01225755b4f57ab5bfd184d97ec3315cc0721cb1854886ae5194563903c48429030eab805abe6442657abf6ee8f03f3b  musl-compat.patch
"
